#include "GameEngine.h"
#include "MenuState.h"
#include "GamePlayState.h"

CGameEngine::CGameEngine()
{
	this->m_curState = this->m_nextState = new CGamePlayState(GAME_PLAY, this);
	this->m_input = new CInput();
}

void CGameEngine::Init(LPDIRECT3DDEVICE9 pD3DDevice, HINSTANCE hInst, HWND hWnd)
{
	this->m_hInst = hInst;
	this->m_hWnd = hWnd;
	this->m_RM = CResourceManager::GetInstance();
	this->m_input->Init(hInst, hWnd);
	this->m_RM->Init(pD3DDevice);

	if (this->m_curState != NULL)
		this->m_curState->Init();
}

void CGameEngine::Update(float gameTime)
{
	// Update Input System
	this->m_input->Update();

	if (this->m_curState == this->m_nextState)
	{
		this->m_curState->Update(gameTime, this->m_input);
	} else
	{
		this->m_curState->Release();
		this->m_curState = this->m_nextState;
		this->m_curState->Init();
	}
}

void CGameEngine::Draw(LPD3DXSPRITE spriteHandler)
{
	this->m_curState->Draw(spriteHandler);
}
